package m3;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

public class Prodecer {
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory f = new ConnectionFactory();
        f.setPort(5672);
        f.setHost("192.168.64.140");
        f.setUsername("admin");
        f.setPassword("admin");
        Channel con = f.newConnection().createChannel();
        /*创建Fanout 交换机对象*/
      //  con.exchangeDeclare("logs","fanout");
        con.exchangeDeclare("logs", BuiltinExchangeType.FANOUT);/*上面那个也行*/
    while (true){
        System.out.println("输入");
        String s = new Scanner(System.in).nextLine();
        /*第二个参数对于Fanout交换机无效,写不写一样*/
        con.basicPublish("logs","",null,s.getBytes());/*如果没有消费者，交换机发送的消息会被废弃*/

        }
    }
}

